package com.ruoyi.web.controller.production.carton;

import java.util.List;

import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.enums.InjectType;
import com.ruoyi.production.service.carton.ICartonAmountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.carton.CartonPurchase;
import com.ruoyi.production.service.carton.ICartonPurchaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 纸箱购买信息Controller
 *
 * @author ruoyi
 * @date 2021-07-10
 */
@RestController
@RequestMapping("/system/cartonPurchase")
@Api(value = "纸箱购买",tags = "纸箱购买相关API")
public class CartonPurchaseController extends BaseController
{
    @Autowired
    private ICartonPurchaseService cartonPurchaseService;
    @Autowired
    private ICartonAmountService cartonAmountService;

    /**
     * 查询纸箱购买信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:cartonPurchase:list')")
    @GetMapping("/list")
    @ApiOperation("获取纸箱购买表信息")
    @ApiImplicitParam(name = "cartonPurchase",value = "纸箱购买实体类",paramType = "body", dataType = "CartonPurchase")
    public TableDataInfo list(CartonPurchase cartonPurchase)
    {
        startPage();
        List<CartonPurchase> list = cartonPurchaseService.selectCartonPurchaseList(cartonPurchase);
        return getDataTable(list);
    }

    /**
     * 导出纸箱购买信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:cartonPurchase:export')")
    @Log(title = "纸箱购买信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出纸箱购买表信息")
    @ApiImplicitParam(name = "cartonPurchase",value = "纸箱购买实体类",paramType = "body", dataType = "CartonPurchase")

    public AjaxResult export(CartonPurchase cartonPurchase)
    {
        List<CartonPurchase> list = cartonPurchaseService.selectCartonPurchaseList(cartonPurchase);
        ExcelUtil<CartonPurchase> util = new ExcelUtil<CartonPurchase>(CartonPurchase.class);
        return util.exportExcel(list, "纸箱购买信息数据");
    }

    /**
     * 获取纸箱购买信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cartonPurchase:query')")
    @GetMapping(value = "/{cartonPurchaseId}")
    @ApiOperation("获取纸箱购买表单个信息")
    @ApiImplicitParam(name = "cartonPurchaseId",value = "纸箱购买实体类主键",paramType = "path", dataType = "Long")
    public AjaxResult getInfo(@PathVariable("cartonPurchaseId") Long cartonPurchaseId)
    {
        return AjaxResult.success(cartonPurchaseService.selectCartonPurchaseById(cartonPurchaseId));
    }

    /**
     * 新增纸箱购买信息并更新纸箱量表
     */
    @PreAuthorize("@ss.hasPermi('system:cartonPurchase:add')")
    @Log(title = "纸箱购买信息", businessType = BusinessType.INSERT)
    @PostMapping
    @PropertyInject(type = InjectType.Insert)
    @ApiOperation("新增纸箱购买表信息")
    @ApiImplicitParam(name = "cartonPurchase",value = "纸箱购买实体类",paramType = "body", dataType = "CartonPurchase")
    public AjaxResult add(@RequestBody CartonPurchase cartonPurchase)
    {
        return toAjax(cartonPurchaseService.insertPurchaseUpdateAmount(cartonPurchase));
    }

    /**
     * 修改纸箱购买信息
     */
    @PreAuthorize("@ss.hasPermi('system:cartonPurchase:edit')")
    @Log(title = "纸箱购买信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @PropertyInject(type = InjectType.Update)
    @ApiOperation("修改纸箱购买表信息")
    @ApiImplicitParam(name = "cartonPurchase",value = "纸箱购买实体类",paramType = "body", dataType = "CartonPurchase")
    public AjaxResult edit(@RequestBody CartonPurchase cartonPurchase)
    {
        return toAjax(cartonPurchaseService.updateCartonPurchase(cartonPurchase));
    }

    /**
     * 删除纸箱购买信息
     */
    @PreAuthorize("@ss.hasPermi('system:cartonPurchase:remove')")
    @Log(title = "纸箱购买信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{cartonPurchaseIds}")
    @ApiOperation("删除纸箱购买表信息")
    @ApiImplicitParam(name = "cartonPurchaseIds",value = "纸箱购买实体类主键数组",paramType = "path", dataType = "Long")
    public AjaxResult remove(@PathVariable Long[] cartonPurchaseIds)
    {
        return toAjax(cartonPurchaseService.deleteCartonPurchaseByIds(cartonPurchaseIds));
    }

}
